const request = require("request"),
    //querystring = require('querystring'),
    compileServer = require('../config-local').compileServer;
//代码编译发送
const compileCode = (req, res) => {
    var hdType = req.body.hdType ? req.body.hdType : 'ardunio';
    request.post({
        headers: "application/json",
        url: `${compileServer}/compiler/${hdType}`,
        json: true,
        body: {
            'hdDataId': req.body.hdDataId,
            'code': req.body.code
        }
    }, (err, httpResponse, body) => {
        if (err || body.result === -1) {
            console.error(err);
            res.send(JSON.stringify({
                result: -1,
                msg: "编译错误,请稍后重试"
            }));
        } else {
            res.send(JSON.stringify({
                result: body.result,
                msg: body.msg,
                code: body.code,
                code2: body.code2
            }));
        }
    });
};
module.exports.compileCode = compileCode;